//
//  AttentionUserCell.m
//  APP_login
//
//  Created by edz on 7/20/21.
//  Copyright © 2021 baicai. All rights reserved.
//

#import "AttentionUserCell.h"
#import "AttentionUserModel.h"
#import "Masonry.h"
#import "UIImageView+WebCache.h"

@interface AttentionUserCell()

@property(nonatomic,strong) UIImageView *imageViewOfCell;
@property(nonatomic,strong) UILabel *nickNameLable;
@property(nonatomic,strong) UILabel *tagLable;
@property(nonatomic,strong) UILabel *daoYouLable;
@property(nonatomic,strong) UIButton *attentionedButton;

@end

@implementation AttentionUserCell

- (instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _imageViewOfCell = [[UIImageView alloc] init];
         [self.contentView addSubview: _imageViewOfCell];
        [_imageViewOfCell mas_makeConstraints:^(MASConstraintMaker *make){
            make.top.left.mas_equalTo(10);
            make.size.mas_equalTo(CGSizeMake(55, 55));
        }];
         
         _nickNameLable = [[UILabel alloc] init];
         [self.contentView addSubview:_nickNameLable];
        [_nickNameLable mas_makeConstraints:^(MASConstraintMaker *make){
            make.top.mas_equalTo(10);
            make.left.mas_equalTo(80);
            make.size.mas_equalTo(CGSizeMake(200, 30));
        }];
         _nickNameLable.font = [UIFont systemFontOfSize:20];
         
         _tagLable = [[UILabel alloc] init];
         [self.contentView addSubview:_tagLable];
         _tagLable.textColor = [UIColor grayColor];
        [_tagLable mas_makeConstraints:^(MASConstraintMaker *make){
            make.top.mas_equalTo(45);
            make.left.mas_equalTo(80);
            make.size.mas_equalTo(CGSizeMake(200, 20));
        }];
         _tagLable.font = [UIFont systemFontOfSize:15];
        
         _daoYouLable = [[UILabel alloc] init];
         _daoYouLable.text = @"道友";
         _daoYouLable.textColor = [UIColor grayColor];
       
         _daoYouLable.textAlignment = NSTextAlignmentCenter;
        
        _attentionedButton = [UIButton buttonWithType:UIButtonTypeSystem];
        [self.contentView addSubview: _attentionedButton];
        [_attentionedButton setTitle:@"已关注" forState:UIControlStateNormal];
        [_attentionedButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [_attentionedButton addTarget:self action:@selector(cancelAttention) forControlEvents:UIControlEventTouchUpInside];
        [_attentionedButton mas_makeConstraints:^(MASConstraintMaker *make){
            make.top.mas_equalTo(30);
            make.right.mas_equalTo(-30);
            make.size.mas_equalTo(CGSizeMake(60, 20));
        }];
        [_attentionedButton.layer setMasksToBounds:YES];
        [_attentionedButton.layer setCornerRadius:10];
        [_attentionedButton.layer setBorderWidth:0.8];
        _attentionedButton.layer.borderColor=[UIColor grayColor].CGColor;
    }
    return self;
}

- (void) cancelAttention{
    [_attentionedButton removeFromSuperview];
    [self.contentView addSubview:_daoYouLable];
    [_daoYouLable mas_makeConstraints:^(MASConstraintMaker *make){
               make.top.mas_equalTo(30);
               make.right.mas_equalTo(-30);
               make.size.mas_equalTo(CGSizeMake(80, 20));
    }];
}

- (void) setModel:(AttentionUserModel *)model{
    _nickNameLable.text = model.userInfo.nickname;
    _tagLable.text = model.userInfo.categoryAlias;
    [_imageViewOfCell sd_setImageWithURL:[NSURL URLWithString:model.userInfo.avatar]];
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
